// Copyright 2015-2016 Brian Smith.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

// TODO: Replace this with use of the array_map feature
// (https://github.com/rust-lang/rust/issues/75243) when it becomes stable.

pub(crate) trait Map<A, B, BArray> {
    fn array_map(self, f: impl Fn(A) -> B) -> BArray;
}

macro_rules! impl_map {
    ( $n:expr, [ $( $elem:ident ),+ ] ) => {
        impl<A, B> Map<A, B, [B; $n]> for [A; $n] {
            #[inline]
            fn array_map(self, f: impl Fn(A) -> B) -> [B; $n] {
                let [ $( $elem ),+ ] = self;
                [ $( f($elem) ),+ ]
            }
        }
    }
}

impl_map!(4, [a, b, c, d]);
impl_map!(8, [a, b, c, d, e, f, g, h]);
